/**
 ********************************************************************
 * @author roocket
 * @file    gpio.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate gpio functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _GPIO_H_
#define _GPIO_H_
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>

#define GPIO_DIR "/sys/class/gpio"
#define MAX_LEN 128

struct gpio_settings {
    int fd;               /* file description for getting value */
    int gpio;             /* which gpio */
    char direction[64];   /* gpio's direction */
    int level;            /* digital level */
    unsigned long data;   /* data via passing */
    /* TBD */
};

/* related to gpio */
int gpio_set_ports(struct gpio_settings *gpio, const char *file);
int gpio_set_unexport(struct gpio_settings *gpio, const char *file);
int gpio_set_export(struct gpio_settings *gpio, const char *file);

int gpio_set_edge_trigger(struct gpio_settings *gpio, char *edge);
int gpio_set_direction(struct gpio_settings *gpio, unsigned int flag);

int gpio_inti_fd(struct gpio_settings *gpio);
int gpio_set_value(struct gpio_settings *gpio, unsigned int value);
int gpio_get_value(struct gpio_settings *gpio, char *value);

#endif /* _GPIO_H_ */

